<%--
    Document   : StockBarang
    Created on : Nov 25, 2013, 12:01:19 AM
    Author     : SONY
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>

<html>
    <head>
        <title>Lihat Stock Barang</title>
    </head>
    <body><%String a = "";

        if ("cabangA".equals(session.getAttribute("area"))) {
            a = "Stock CABANG A";
        }
        if ("cabangB".equals(session.getAttribute("area"))) {
            a = "Stock CABANG B";
        }
        if ("cabangA".equals(session.getAttribute("area"))) {
            a = "Stock CABANG B";
        }%>
        <form method="post">

            <h2 align="center" style="color:black"> Lihat Tabel Stock Barang </h2>
            <% if ("Manajer".equals(session.getAttribute("area"))) {%>


            <p>Pilih Lokasi Cabang : </p>
            <select name="LokasiCabang" size="1">
                <option value="0">Semua Barang</option>
                <option value="1">Cabang A</option>
                <option value="2">Cabang B</option>
                <option value="3">Cabang C</option>
            </select>
            <input type="submit" value="submit"  />
            <p></p>

            <%
                    a = "Halaman Manajer";
                }
                try {

                    Connection con = koneksi.CekKoneksi.open();
                    String kode = request.getParameter("LokasiCabang");
                    Statement stat = con.createStatement();
                    ResultSet rs = null;
                    String in1 = null;
                    if ("Manajer".equals(session.getAttribute("area"))) {
                        if (kode == null || "0".equals(kode)) {
                        out.print("Tabel Barang Semua Cabang");
                        in1 = "SELECT kode_barang,jumlah,nama_barang,harga_barang FROM cabanga "
                                + "UNION SELECT kode_barang,jumlah,nama_barang,harga_barang FROM cabangb "
                                + "Union SELECT kode_barang,jumlah,nama_barang,harga_barang FROM cabangc";

                    }
                        if (kode.equals("1")) {
                            out.print("Tabel Barang Cabang A");
                            in1 = "select * from CABANGA ";

                        } else if (kode.equals("2")) {
                            out.print("Tabel Barang Cabang B");
                            in1 = "select * from CABANGB ";

                        } else if (kode.equals("3")) {
                            out.print("Tabel Barang Cabang C");
                            in1 = "select * from CABANGC ";

                        }
                        
                    } else {
                        in1 = "select * from " + session.getAttribute("area");


                    }
                    rs = stat.executeQuery(in1);

            %>
          <br>  <%=a%>
            <table border="1">
                <tr>
                    <td>Kode Barang</td>
                    <td>Nama Barang</td>
                    <td>Harga Barang</td>
                    <td>Jumlah</td>
                </tr>
                <%
                    while (rs.next()) {
                %>


                <TR>
                    <TD><%=rs.getString("KODE_BARANG")%></TD>
                    <TD><%=rs.getString("NAMA_BARANG")%></TD>
                    <TD><%=rs.getString("HARGA_BARANG")%></TD>
                    <TD><%=rs.getString("JUMLAH")%></TD>
                </TR>
                <% }
                %>
            </table>
            <%
                    rs.close();
                } catch (Exception ex) {
                    out.println("Can't connect to database.");
                }
            %>
        </form>
    </body>
</html>